#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin >> n;
	for(int i = 1 ; i <= n ; i++){
		int x , y;
		char a[105][105];
		cin >> x >> y;
		for(int j = 1 ; j <= x ; j++){
			for(int k = 1 ; k <= y ; k++){
				cin >> a[j][k];
			}
		}
		int flag = 0;
		for(int j = 1 ; j <= (x - 3) ; j++){
			for(int k = 1 ; k <= (y - 3) ; k++){
				if(a[j][k] == '0' && a[j][k + 1] == '0' && a[j][k + 2] == '0' && a[j][k + 3] == '0'){
					if(a[j + 1][k] == '0' && a[j + 1][k + 1] == '1' && a[j + 1][k + 2] == '1' && a[j + 1][k + 3] == '0'){
						if(a[j + 2][k] == '0' && a[j + 2][k + 1] == '1' && a[j + 2][k + 2] == '1' && a[j + 2][k + 3] == '0'){
							if(a[j + 3][k] == '0' && a[j + 3][k + 1] == '0' && a[j + 3][k + 2] == '0' && a[j + 3][k + 3] == '0'){
								flag = 1;
							}
						}
					}
				}
			}
		}
		if(flag == 1){
			cout << "Yes" << endl;
		}
		if(flag == 0){
			cout << "No" << endl;
		}
	}
	return 0;
}
